package cc.mrbird.febs.common.formatter;

import cc.mrbird.febs.common.enums.SensitiveType;
import cc.mrbird.febs.common.utils.DesensitizedUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.Formatter;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Locale;


public class DesensitizedFormatterOfNum implements Formatter<BigDecimal> {
    private SensitiveType type;

    public SensitiveType getTypeEnum() {
        return type;
    }

    public void setTypeEnum(SensitiveType type) {
        this.type = type;
    }

    @Override
    public BigDecimal parse(String valueStr, Locale locale) throws ParseException {
        BigDecimal ret = new BigDecimal(0);
        if (StringUtils.isNotBlank(valueStr)) {
            switch (type) {
                case INCOME:
                    ret = DesensitizedUtils.income(valueStr);
                    break;
                default:
            }
        }
        return ret;
    }

    @Override
    public String print(BigDecimal s, Locale locale) {
        return "***";
    }
}